<html>
	<head>
		<link rel="stylesheet" href="/admin/stylesheets/admin.css" />
	</head>
	<body background="/images/bg.gif" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
		<table width="100%" cellpadding="0" cellspacing="0" border="0" style="height:100%">
			<tr class="formbackground">
				<td class="formbackground"><table width="100%" cellpadding="3" cellspacing="1" border="0" style="height:100%">
					<tr class="formcells">
						<td width="100%" height="20" class="formheader"><b>Menu Structure</b></td>
					</tr>
					<tr class="formcells">
						<td class="formcells" valign="top"><span height="100%" id="directory"></span></td>
					</tr>
				</table></td>
			</tr>
		</table>
		<script>
				/*
				-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
				- indexes for the menu array are :-
					0	identifier,
					1	label,
					2	url,
					3	depth,	
					4	children,	
					5	parent,	
					6	channels,	
					7	siblings,	
					8	group options Array(),	
					9	order,
					10	stylesheet,
					11	theme
				-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
				*/
				indent			= Array();
 				toggle		 	= Array();
 				toggle[-1] 		= Array(-1,true);
 				counter			= Array();
 				counter[0]=1;
				menu_list		= parent.menu_list;
				var count = Array();
				
				for (index=0;index < menu_list.length;index++){
					toggle[index]	= Array(menu_list[index][0],false);
				}

				
				
				function confirm_deletion(loc){
					if (confirm("Are your Sure?")){
						window.location=loc;
					}
				}
				function edit(loc){
					for(index=0;index < menu_list.length;index++){
						if (menu_list[index][0]==loc){
							found					= index;
						}
					}
					d 								= parent.document.layout_form;
					tmpstr 							= new String(menu_list[found][2]);
					pos 							= tmpstr.lastIndexOf("/");
					external_link					= tmpstr.indexOf("://");
					admin_link						= tmpstr.indexOf("admin/");
					if (((admin_link==-1) && (external_link==-1)) && (pos!=-1)){
						if (pos>0){
							directory_location	 	= tmpstr.substring(0,pos+1);
						}else{
							if(pos=0){
								pos					= 1;
							}
							directory_location	 	= "/";
						}
						url 						= tmpstr.substring(pos+1,tmpstr.length);
					} else {
						directory_location	 		= "/";
						if (admin_link==-1){
							url						= tmpstr;
						}else{
							url						= tmpstr.substring(1,tmpstr.length);
						}
					}
					/*
					-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
					- menu_theme
					-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
					*/
					if (d.menu_theme.name+''!='null' && d.menu_theme.name+''!='undefined'){
						for(index=0;index<d.menu_theme.options.length;index++){
							if (menu_list[found][11]==d.menu_theme.options[index].value){
								d.menu_theme.options[index].selected=true;
							} else {
								d.menu_theme.options[index].selected=false;
							}
						}
					}
					/*
					-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
					- menu_stylesheet
					-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
					*/
					if (d.menu_stylesheet.name+''!='null' && d.menu_stylesheet.name+''!='undefined'){
						for(index=0;index<d.menu_stylesheet.options.length;index++){
							if (menu_list[found][10]==d.menu_stylesheet.options[index].value){
								d.menu_stylesheet.options[index].selected=true;
							} else {
								d.menu_stylesheet.options[index].selected=false;
							}
						}
					}
					
					/*
					-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
					- menu_order
					-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
					*/
					d.menu_order.options.length=0;
					for (index=0; index <= menu_list[found][7]+1;index++){
						d.menu_order.options[d.menu_order.options.length] = new Option(index+1,index+1);
						if (menu_list[found][9]==index+1){
							d.menu_order.options[index].selected=true;
						}
					}
					
					dir_found=-1;
					for (index=0; index < d.menu_directory.options.length;index++){
						if (d.menu_directory.options[index].text==directory_location){
							dir_found=index;
						 	d.menu_directory.options[index].selected=true;
						}
					}
					if (dir_found==-1){
						d.menu_directory.options[0].selected=true;
						url = new String(menu_list[found][2]).substring(1);
					}
					
					
					//menu_group_access
					groups_options = menu_list[found][8];
					group_access = parent.document.layout_form.elements['menu_group_access[]'];
					for (x=0;x < group_access.length;x++){
						group_access[x].checked=false
						for (y=0;y < groups_options.length;y++){
							if (group_access[x].value == groups_options[y]){
								group_access[x].checked=true
							}
						}
					}
					
					display_options = menu_list[found][6];
					display_access = parent.document.layout_form.elements['menu_display[]'];
					for (x=0;x < display_access.length;x++){
						display_access[x].checked=false
						for (y=0;y < display_options.length;y++){
							if (display_access[x].value == display_options[y]){
								display_access[x].checked=true
							}
						}
					}
					
					
					for (x=0;x < d.menu_parent.length;x++){
						if (d.menu_parent[x].value == menu_list[found][5]){
							d.menu_parent[x].selected=true
						}
					}
					
					d.menu_identifier.value	= menu_list[found][0];
					d.menu_label.value		= menu_list[found][1];
					d.menu_url.value		= url;
					d.previous_url.value	= menu_list[found][2];
					
					parent.document.LAYOUT_REMOVE_MENU.src='images/button_REMOVE.gif';
//					d.LAYOUT_REMOVE_MENU.style.visibility='visible';
				}
		
				function link_toggle(linkid){
					for (index=0,len=menu_list.length;index < len;index++){
						if (linkid==menu_list[index][0]){
							toggle[index][1] = !toggle[index][1];
						}
					}
					draw_menu();
				}
		
				function draw_menu(){
					//menu_list = ;
					level = 0;
					prev_level = 0;
					depth =0;
					for (index=0,len=menu_list.length;index < len;index++){
						if (depth < menu_list[index][3]){
							depth=menu_list[index][3];
						}
					}
					output ='<table width="100%" border="0" cellpadding="0" cellspacing="0">\n';
					if (!toggle[-1][1]){
						output +='<tr>\n<td width="10"><a class="layout_menu_folder" href="javascript:link_toggle(-1);"><img src="images/plus.gif" border="0"/></a></td>\n<td width="100%" colspan="'+(depth+1)+'">&nbsp;Root</td>\n</tr>\n';
					}else{
						output +='<tr>\n<td width="10"><a class="layout_menu_folder" href="javascript:link_toggle(-1);"><img src="images/minus.gif" border="0"/></a></td>\n<td width="100%" colspan="'+(depth+1)+'">&nbsp;Root</td>\n</tr>\n';
						output += display_children(1,-1);
					}
					output+="</table>\n";
					document.all.directory.innerHTML=output;
				}
				
				function display_children(d,loc){
					var index=0;
					var output="";
					var NEW_DEPTH=d;
					var total = counter[d];
					count[d]=0
					for (var index=0;index < menu_list.length;index++){
						if (menu_list[index][5]==loc){
							indent[d] ="";
							
							for (var depth_index=1 ; depth_index < NEW_DEPTH+1 ; depth_index++){
								if (depth_index<d){
									if (count[depth_index]==menu_list[index][7]){
										//alert(depth_index+"  "+count[depth_index]+" "+menu_list[index][7])
										indent[d] +='\n<td width="10"><img src="images/folder_down.gif" border="0"/></td>';
									} else {
										if (menu_list[index][7] < count[depth_index]){
											if (depth_index<(d)){
												indent[d] +='\n<td width="10"><img src="images/folder_down.gif" border="0"/></td>'; //folder_down
											}else{
												indent[d] +='\n<td width="10"><img src="images/folder_junction.gif" border="0"/></td>';
											}
										}else{
											//alert(menu_list[index][7]+ " " +depth_index+ " " +d+ " " +count[depth_index]+ " " +count[d])
											indent[d]     +='\n<td width="10"><img src="images/1x1.gif" border="0"/></td>';
										}
									}
								}else{
									if (count[depth_index]==menu_list[index][7]){
										indent[d] +='\n<td width="10"><img src="images/folder_bottom_corner.gif" border="0" width="19" height="18"/></td>';
									} else if (count[depth_index] < menu_list[index][7]){
										indent[d] +='\n<td width="10"><img src="images/folder_junction.gif" border="0" width="19" height="18"/></td>';
									} else if (count[depth_index] > menu_list[index][7]){
										indent[d] +='\n<td width="10"><img src="images/1x1.gif" border="0" width="19" height="18"/></td>';
									} else {
										indent[d] +='\n<td width="10"><img src="images/folder_down.gif" border="0" width="19" height="18"/></td>';
									}
								}
							}
							if (menu_list[index][4]>0){
								if (!toggle[index][1]){
									output 		+= '<tr>'+indent[d];
									output 		+= '\n<td width="10"><a class="layout_menu_folder" href="javascript:link_toggle('+menu_list[index][0]+');"><img src="images/plus.gif" border="0"/></a></td>\n<td width="100%" colspan="'+((depth+1)-d)+'">&nbsp;<a href="javascript:edit('+menu_list[index][0]+');">'+menu_list[index][1]+'</a></td>\n</tr>\n';
								}else{
									
									output 		+= '<tr>'+indent[d];
									output		+= '\n<td width="10"><a class="layout_menu_folder" href="javascript:link_toggle('+menu_list[index][0]+');"><img src="images/minus.gif" border="0"/></a></td>\n<td width="100%" colspan="'+((depth+1)-d)+'">&nbsp;<a href="javascript:edit('+menu_list[index][0]+');">'+menu_list[index][1]+'</a></td>\n</tr>\n';
									output 		+= display_children(NEW_DEPTH+1,toggle[index][0]);
								}
							} else {
								output +='<tr>'+indent[d];
								output +='\n<td><img src="images/folder_right.gif" border="0" /></td>\n<td width="100%" colspan="'+((depth+1)-d)+'">&nbsp;<a href="javascript:edit('+menu_list[index][0]+');">'+menu_list[index][1]+'</a></td>\n</tr>\n';
							}
							count[d]++
						}
					}
					return output;
				}
				
				function build_location_combo(parent_id,first) {
					d 	= parent.document.layout_form;
					
					if (1==first){
						d.menu_parent.options.length=1;
					}
					for (var index=0;index < menu_list.length;index++){
						if (menu_list[index][5]==parent_id){
							textinput = "";
							for (var spacer_index=0;spacer_index < menu_list[index][3];spacer_index++){
								if (spacer_index < (menu_list[index][3]-1)){
									textinput += "   ";
								} else {
									if (menu_list[index][4]>0){
										textinput += " - ";
									}else{
										textinput += "   ";
									}
								}
							}
							textinput += menu_list[index][1];
							d.menu_parent.options[d.menu_parent.options.length] = new Option(textinput,menu_list[index][0]);
							build_location_combo(menu_list[index][0],0);
						}
					}
				}
				
				draw_menu();
				build_location_combo(-1,1);
				d	= parent.document.layout_form;
				parent.document.LAYOUT_REMOVE_MENU.src='images\\1x1.gif';
//				d.LAYOUT_REMOVE_MENU.style.visibility='hidden';
						
			</script>
	</body>
</html>